<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WebSocket Demo</title>
</head>
<body>
    <h1>WebSocket Demo</h1>
    <div id="message-container"></div>

    <script>
        var wsScheme = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
        var wsPath = wsScheme + window.location.host + '/ws/chat/';

        var ws = new WebSocket(wsPath);

        ws.onopen = function(event) {
            console.log('WebSocket connected');
        };

        ws.onmessage = function(event) {
            var message = JSON.parse(event.data).message;
            var messageContainer = document.getElementById('message-container');
            messageContainer.innerHTML += '<p>' + message + '</p>';
        };

        ws.onerror = function(event) {
            console.error('WebSocket error:', event);
        };

        ws.onclose = function(event) {
            console.log('WebSocket closed');
        };
    </script>
</body>
</html>
